package com.aloda.utils;

import com.aloda.constant.RegexConstant;

import java.util.regex.Pattern;

/**
 * @author aloda
 */
public class RegexUtils {

    /**
     * 校验密码 正确-true 错误-false
     * @param password
     * @return
     */
    public static boolean checkPassword(String password) {
        // 校验密码
        Pattern passwordPattern = Pattern.compile(RegexConstant.PASSWORD_REGEX);
        return password != null
                && !password.isEmpty()
                && passwordPattern.matcher(password).matches();
    }

    /**
     * 校验邮箱 正确-true 错误-false
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        // 校验邮箱
        Pattern emailPattern = Pattern.compile(RegexConstant.EMAIL_REGEX);
        return email != null
                && !email.isEmpty()
                && emailPattern.matcher(email).matches();
    }

    /**
     * 校验名称 正确-true 错误-false
     * @param name
     * @return
     */
    public static boolean checkName(String name) {
        // 校验名称
        Pattern namePattern = Pattern.compile(RegexConstant.NAME_REGEX);
        return name != null
                && !name.isEmpty()
                && namePattern.matcher(name).matches();
    }
}
